package test;

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import com.amani.model.AmnProduct;
import com.amani.services.ICommonService;

/**
 * Servlet implementation class testServlet
 */
@WebServlet("/testServlet")
public class testServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public testServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 String serviceURL = "http://localhost:8080/AMNCommonService/services/CommonService";  
	        try {  
	            Service serviceModel = new ObjectServiceFactory().create(ICommonService.class);  
	            XFire xfire = XFireFactory.newInstance().getXFire();  
	            XFireProxyFactory factory = new XFireProxyFactory(xfire);  
	            ICommonService client = null;  
	            try {  
	                client = (ICommonService) factory.create(serviceModel, serviceURL);  
	            } catch (MalformedURLException e) {  
	                System.out.println("Client call webservice has exception: " + e.toString());  
	            }  
//	            List<AmnProduct> result = client.loadHotProducts();  
//	            System.out.print(result);  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
